//bases on Mark Nelson implementation of GST

package ru.osu.acm.system.sourcediff;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class Uzel {
    private ST ST;

    private Uzel SufUzel;
    private Map<Character, Rebro> Rebros;
    private int name;

    public Uzel(Uzel Uzel, Uzel SufUzel) {
        this(Uzel.ST, SufUzel);
    }

    public Uzel(ST ST, Uzel SufUzel) {
        this.ST = ST;
        name = ST.getNewUzelNumber();

        this.SufUzel = SufUzel;
        Rebros = new HashMap<Character, Rebro>();
    }

    public char charAt(int Ind) {
        return ST.getText().charAt(Ind);
    }

    public void addRebro(int charInd, Rebro Rebro) {
        Rebros.put(charAt(charInd), Rebro);
    }

    public void delRebro(int charInd) {
        Rebros.remove(charAt(charInd));
    }

    public Rebro findRebro(char ch) {
        return Rebros.get(ch);
    }

    public Uzel getSufUzel() {
        return SufUzel;
    }

    public void setSufUzel(Uzel SufUzel) {
        this.SufUzel = SufUzel;
    }

    public Collection<Rebro> getRebros() {
        return Rebros.values();
    }

    @Override
    public String toString() {
        return ((Integer) name).toString();
    }

    @Override
    public int hashCode() {
        return name;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if ((obj == null) || (obj.getClass() != this.getClass()))
            return false;

        Uzel Uzel = (Uzel) obj;
        return name == Uzel.name;
    }
}

